'use strict';

module.exports = {
	/**
	 * 获取用户充值数据接口
	 * @url api/pub/data/analyzer/getRecharge 报表分析使用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();
		const dbcmd = db.command;

		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		let dbName = "report_channel_day"; // 表名
		console.log('usrInfo.username='+userInfo.username);
		console.log('usrInfo.role='+userInfo.role);
		console.log('usrInfo._id='+userInfo._id);
		if (userInfo.username == "admin") {
			res = await vk.baseDao.getTableData({
				dbName,
				data,
				whereJson: { // 条件
				},
				sortArr: [{ "name":"date_time", "type":"desc" }]
			});
			// 业务逻辑结束-----------------------------------------------------------
			return res;
		}
		if (userInfo.role.includes("middleman")) {
			res = await vk.baseDao.getTableData({
				dbName,
				data,
				whereJson: { // 条件
				    middleman_id: userInfo._id
				},
				sortArr: [{ "name":"date_time", "type":"desc" }]
			});
			// 业务逻辑结束-----------------------------------------------------------
			return res;
		}
		if (userInfo.role.includes("agent")) {
			res = await vk.baseDao.getTableData({
				dbName,
				data,
				whereJson: { // 条件
				    agent_id: userInfo._id
				},
				sortArr: [{ "name":"date_time", "type":"desc" }]
			});
			// 业务逻辑结束-----------------------------------------------------------
			return res;
		}
		
	}
}